﻿@{
    ViewBag.Title = "GuarCompanyAdd";
    Layout = "~/Views/Shared/_Base.cshtml";
}

<div style="padding-left:20px;">
    <strong><span style="font-size:14px">增加担保公司</span></strong>
    <br /><br />
<table border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td valign="middle" width="80px" align="right">
            <span style="color:Red">*</span>公司名称:&nbsp;
        </td>
        <td>
            <input type="text" id="txtGuarCompany" placeholder="公司名称" class="col-xs-10 col-sm-5" style="width:600px;" />
        </td>
    </tr>
    <tr>
        <td valign="middle" align="right">
            <span style="color:Red">*</span>公司简介:&nbsp;
        </td>
        <td>
            <textarea id="txtSummary" placeholder="公司简介" class="col-xs-10 col-sm-5" style="width:600px; height:100px;"></textarea>
        </td>
    </tr>
    <tr>
        <td><div style="height:10px;"></div></td>
    </tr>
    <tr>
        <td valign="middle" align="right">
            公司描述:&nbsp;
        </td>
        <td>
            <textarea id="txtDescription" placeholder="公司描述" class="col-xs-10 col-sm-5" style="width:600px; height:100px;"></textarea>
        </td>
    </tr>
    <tr>
        <td><div style="height:10px;"></div></td>
    </tr>
    <tr valign="middle">
        <td valign="middle" align="right">
            公司图标:&nbsp;
        </td>
        <td valign="middle">
            <input type="button" id="btnCpyIconUpload" value="点击上传" style="width:90px; float:left;" class="btn btn-default" onclick="LoadUploadControl(1)" />
            <div id="imgCompanyIcon" style="float:left; margin-left:10px; vertical-align:middle;"></div>
        </td>
    </tr>
    <tr>
        <td><div style="height:10px;"></div></td>
    </tr>
    <tr>
        <td valign="middle" align="right">
            资质图片:&nbsp;
        </td>
        <td valign="middle">
            <input type="button" id="btnQualifiImagesUpload" value="点击上传" style="width:90px; float:left;" class="btn btn-default" onclick="LoadUploadControl(2)" />
            <div id="imgQualifiImages" style="float:left;"></div>
        </td>
    </tr>
    <tr>
        <td><div style="height:10px;"></div></td>
    </tr>
    <tr>
        <td valign="middle" align="right">
            协议图片:&nbsp;
        </td>
        <td valign="middle">
            <input type="button" id="btnAgreementImagesUpload" value="点击上传" style="width:90px; float:left;" class="btn btn-default" onclick="LoadUploadControl(3)" />
            <div id="imgAgreementImages" style="float:left;"></div>
        </td>
    </tr>
    <tr style="height:50px;">
        <td valign="middle" align="right">
            &nbsp;
        </td>
        <td>
            <span id="lblmsg" style="color:Red">&nbsp;</span>
        </td>
    </tr>
    <tr>
        <td valign="middle" align="right">
            
        </td>
        <td>
            <button type="button" id="btnCancel" class="btn btn-default">
            关闭</button>
            <button type="button" id="btnSave" class="btn btn-primary">
            保存</button>
        </td>
    </tr>
</table>
</div>
<div id="fileuploadframe" style="display:none; position:absolute; width:480px;height:380px;z-index:99999;">
    <div style="height:25px;width:100%; border-bottom:1px solid #ccc">
    <div style="float:right;width:80px; height:23px; line-height:23px;">
        <a href="javascript:;"><img alt="关闭" style="border:none;" id="btnflfclose" src="/Content/plugins/swfupload/closelabel.gif"/></a>
    </div>
    </div>
    <div style="width:100%;height:354px;">
        <div id="fileuploadframe_imgbox" style="width:100%;height:310px; overflow:auto;">
        </div>
        <div id="fileuploadframe_controlbox" style="width:100%;height:45px;">
            <div id="fileupload" style="float:left;width:130px;"></div>
            <div id="fileuploadframe_hint" style="font-size:12px;padding-top:20px; float:left;width:280px;"></div>
            <div id="fileuploadframe_btnsubmit" style="float:right;"><input id="btnupload" type="button" class="btn btn-default"" value="完成" /></div>
        </div>
    </div>
</div>
@section tail{
    <script src="/Content/plugins/swfupload/jquery.swfupload.js" type="text/javascript"></script>
    <script src="/Content/plugins/swfupload/swfupload.js" type="text/javascript"></script>
    <script src="/Content/scripts/plug.js" type="text/javascript"></script>
    <script src="/Content/plugins/fancybox/jquery.fancybox-1.3.4.pack.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(function () {
            $("#btnSave").click(function () {
                if (validate()) {
                    var imgCpyIconPath = $("#imgCompanyIcon img")[0].title;
                    var imgQuqImgsPath = $('#imgQualifiImages img')[0].title;
                    var imgAgtImgsPath = $('#imgAgreementImages img')[0].title;
                    $.ajax({
                        url: "/GuarCompany/GuarCompanySave",
                        data: "editType=1" + "&guarCompanyId=0"
                            + "&companyName=" + $("#txtGuarCompany").val() + "&logoImage=" + imgCpyIconPath
                            + "&summary=" + $("#txtSummary").val() + "&description=" + $("#txtDescription").val()
                            + "&qualificationsImages=" + imgQuqImgsPath + "&agreementImages=" + imgAgtImgsPath,
                        type: "post",
                        success: function (result) {
                            if (result == "True") {
                                bootbox.alert("<span style='font-size:14px;'><i style='color:green;' class=' icon-ok-sign bigger-290'></i>保存成功</span>", '300px', function () {
                                    location.href = decodeURIComponent("/GuarCompany/Index");
                                });
                            }
                            else {
                                bootbox.alert("<span style='font-size:14px;'><i style='color:green;' class='icon-remove-sign bigger-290'></i>保存失败</span>", '300px');
                            }
                        }
                    });
                }
            });

            $("#btnCancel").click(function () {
                location.href = decodeURIComponent("/GuarCompany/Index");
            });
        });

        function validate() {
            $("#lblmsg").html("");
            var guarcompany = $("#txtGuarCompany").val();
            if (guarcompany == "") {
                $("#txtGuarCompany").focus();
                $("#lblmsg").html('公司名称不能为空');
                return false;
            }
            var guarcompanyreg = /^[A-Za-z0-9\u4e00-\u9fa5]+$/;
            if (!guarcompanyreg.test($("#txtGuarCompany").val())) {
                $("#txtGuarCompany").focus();
                $("#lblmsg").html('公司名称不能包含特殊符号');
                return false;
            }
            var sum = $("#txtSummary").val();
            if (sum == "") {
                $("#txtSummary").focus();
                $("#lblmsg").html('公司简介不能为空');
                return false;
            }
            return true;
        }

        var swf = new plug.SwfUpload();
        function LoadUploadControl(imagetype) {
            new plug.PopFrame().OpenFrame('fileuploadframe', 'btnflfclose', function () {
                swf.Bind('fileupload', {
                    upload_url: "/GuarCompany/SWFPrepareUpload",
                    file_types: "*.jpg;*.png",
                    file_types_description: "jpg或png格式",
                    commitbtn: 'btnupload',
                    commiturl: '/GuarCompany/SWFUpload',
                    commitdata: '',
                    onDialogStart: function () {
                        $('#fileuploadframe_imgbox').children('#uploadframe_nophotobox').remove();
                    },
                    onLoad: function () {
                        $('#fileuploadframe_imgbox').append(
                            $('<div id="uploadframe_nophotobox" style="width:130px; padding-top:120px;margin-left:auto; margin-right:auto;"/>').append(
                                $('<img src="/Content/plugins/swfupload/no_photo.png" alt="noPhoto" />')
                            )
                        );
                        $('#fileuploadframe_hint').text('选择不大于5MB的PNG、JPG图片');
                    },
                    onAppend: function (event, file) {
                        $('#fileuploadframe_imgbox').append(
                            $('<div id="' + file.name.replace('.', '_') + '" style="margin-right:8px;margin-top:5px;float:left;width:113px;height:113px;padding:5px;border:1px solid #ccc;"></div>')
                                .append($('<div style="width:20px;margin-left:auto;margin-right:auto;padding-top:50px;"><img alt="loading" src="/Content/plugins/swfupload/frameload.gif" /></div>'))
                        );
                    },
                    onError: function (event, file, errorCode, message) {
                        if (errorCode == -110) {
                            alert('文件：' + file.name + '过大，请选择不超过7MB的文件');
                        }
                        else {
                            alert('文件：' + file.name + '上传失败，请稍后再试');
                            var id = file.name.replace('.', '_');
                            if ($('#' + id)) {
                                $('#' + id).remove();
                            }
                        }
                    },
                    onSuccess: function (event, file, serverData) {
                        var data = eval('(' + serverData + ')');
                        var id = file.name.replace('.', '_');
                        if ($('#' + id)) {
                            $('#' + id).attr('id', data.name.replace('.', '_'))
                                .html('<div><img style="width:115px;height:95px;" alt="' + data.name.replace('.', '_') + '" src="' + data.path + '" /></div>' +
                                '<div style="padding-top:2px;float:right;cursor:pointer;" onclick="javascript:swf.DeleteItem(this);"><img alt="删除" style="width:16px;height:16px;" src="/Content/plugins/swfupload/Trash_Delete.png" /></div>');
                            swf.PutImage({ name: data.name, path: data.path, horizontal: data.horizontal.toString() });
                        }
                    },
                    commitComplete: function (files) {
                        $('#btnflfclose').trigger('click');
                        var width = 95, height = 115;
                        for (var i = 0, len = files.length; i < len; i++) {
                            if (/^true$/i.test(files[i].horizontal.toString())) {
                                width = 115;
                                height = 95;
                            }

                            if (imagetype == 1) {
                                $('#imgCompanyIcon').html(
                                   $('<img alt="' + files[i].name + '"title="' + files[i].name + '" src="' + files[i].path + '" style="width:' + width + 'px;height:' + height + 'px;"/>'));
                            }
                            else if (imagetype == 2) {
                                $('#imgQualifiImages').html(
                                   $('<img alt="' + files[i].name + '"title="' + files[i].name + '" src="' + files[i].path + '" style="width:' + width + 'px;height:' + height + 'px;"/>'));
                            }
                            else if (imagetype == 3) {
                                $('#imgAgreementImages').html(
                                   $('<img alt="' + files[i].name + '"title="' + files[i].name + '" src="' + files[i].path + '" style="width:' + width + 'px;height:' + height + 'px;"/>'));
                            }
                        }
                    }
                });
            }, function () {
                $('#fileuploadframe_imgbox').html('');
                $('#fileupload').html('');
                swf.uninstall();
            });
        }

        $('.resource').fancybox();

</script>
}